package com.cxrj.zhsq.userManage.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cxrj.zhsq.userManage.dao.AppUserBlackMapper;
import com.cxrj.zhsq.userManage.entity.AppUserBlack;
import com.cxrj.zhsq.userManage.service.AppUserBlackService;

@Service
public class AppUserBlackServiceImpl implements AppUserBlackService {

	@Resource
	private AppUserBlackMapper appUserBlackMapper;

	@Override
	public Map<String, Object> insertAppUserBlack(String userId, String userBlackId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		AppUserBlack appUserBlack = new AppUserBlack();
		appUserBlack.setId(UUID.randomUUID().toString());
		appUserBlack.setUserId(userId);
		appUserBlack.setUserBlackId(userBlackId);
		Integer c = appUserBlackMapper.insertSelective(appUserBlack);
		resultMap.put("result", 0);
		if (c > 0) {
			resultMap.put("result", 1);
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> deleteAppUserBlack(String userId, String userBlackId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		AppUserBlack appUserBlack = new AppUserBlack();
		appUserBlack.setUserId(userId);
		appUserBlack.setUserBlackId(userBlackId);
		Integer c = appUserBlackMapper.deleteByUser(appUserBlack);
		resultMap.put("result", 0);
		if (c > 0) {
			resultMap.put("result", 1);
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> selectAppUserBlack(String userId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<AppUserBlack> list = appUserBlackMapper.selectAppUserBlack(userId);
		for (AppUserBlack appUserBlack : list) {
			if (appUserBlack.getUserName() == null) {
				appUserBlack.setUserName("超級用户");
			}
		}
		resultMap.put("list", list);
		return resultMap;
	}

}
